<?php
/**
 * Created by PhpStorm.
 * User: 氓羽
 * Date: 2018-4-22
 * Time: 21:12
 */
    require ('../smarty/Smarty.class.php');

    $smarty = new Smarty();

    //Smarty “自编口诀-五配置两方法”
    //五配置介绍
    $smarty -> left_delimiter = "{"; //左定界符
    $smarty -> right_delimiter = "}"; //右定界符
    $smarty -> template_dir = "tpl"; //html模板的地址
    $smarty -> compile_dir  = "template_c"; //模板编译生成的文件
    $smarty -> cache_dir = "cache"; //缓存

    //以下是开启缓存的另外两个配置/因为通常不用Smarty的缓存机制，所以此项为了解
    $smarty -> caching = true; //开启缓存
    $smarty -> cache_lifetime = 120;



    $smarty->assign('articletitle', 'I ate an apple');
    $arr = array('title'=> 'smartyStudy', 'author' => '小明');
    $smarty->assign('arr', $arr);

    //获取当前时间
    $t = time();
    //将当前时间赋值给smarty自定义变量
    $smarty->assign('time',$t);

    //定义一个空的变量
    $smarty->assign('value01','');

    //转码url地址
    $smarty->assign('url','https://www.imooc.com/video/1059');

    //定义一个换行自动转成<br>标签的变量
    $smarty->assign('articlecontent','你好
        还行
        不错吧
    ');

    //smarty中的if判断语句
    $smarty->assign('score', 95);

    //smarty中的list循环遍历方法
    $articlelist = array(
        array(
            "title"=>"文章1",
            "author"=>"Tom",
            "content"=>"12345678901234567890"
        ),
        array(
            "title"=>"文章2",
            "author"=>"Join",
            "content"=>"(*******)########(!!!!!!!!!!!!!!!!!!!!!!)0"
        )
    );
    $smarty->assign("articlelist", $articlelist);

    //自定义输出文件
    $smarty->display('smarty_test.tpl');

